#include "contextviewerwidget.h"

ContextViewerWidget::ContextViewerWidget(QGraphicsItem *parent) :
    QGraphicsWidget(parent)
{
    init( 0, 0, 0 );
}

ContextViewerWidget::ContextViewerWidget(int t, int s, int e, QGraphicsItem *parent) :
    QGraphicsWidget(parent)
{
    init( t, s, e );
}

void ContextViewerWidget::init(int t, int s, int e)
{
    setGeometry(0, 0, 100, 100);

    bigRect = new QGraphicsRectItem(this);
    littleRect = new QGraphicsRectItem(this);
    total = t;
    start = s;
    end = e;
    resizeRects();

    QColor c;
    c.setRgb(100, 100, 100);

    QBrush b;
    b.setColor(c);
    bigRect->setBrush(b);
    bigRect->setPen(Qt::NoPen);

    c.setRgb( 200, 200, 200 );
    b.setColor(c);
    littleRect->setBrush(b);
    littleRect->setPen(Qt::NoPen);
}

//-------------------------------SIZE AND SHAPE-----------------------------------
void ContextViewerWidget::setGeometry(const QRectF &geom)
{
    prepareGeometryChange();
    QGraphicsWidget::setGeometry(geom);
    //setPos(geom.topLeft());

    resizeRects();
}

void ContextViewerWidget::setGeometry( qreal x, qreal y, qreal w, qreal h )
{
    setGeometry(QRect(x, y, w, h));
}

void ContextViewerWidget::resizeRects()
{
//    bigRect->setRect( boundingRect() );

//    int bigRectHeight = boundingRect().height();
//    int diff = end - start;
//    float ratio = (float) diff / (float) total;
//    float littleRectHeight = ratio * (float) bigRectHeight;
//    float littleRectTopPos = (float) start / (float) total * (float) bigRectHeight;

//    littleRect->setRect(boundingRect().x(), littleRectTopPos, boundingRect().width(), littleRectHeight);
}

QRectF ContextViewerWidget::boundingRect() const
{
    return QRectF(QPointF(0,0), geometry().size());
}

QPainterPath ContextViewerWidget::shape() const
{
    QPainterPath path;
    path.addRect(boundingRect());
    return path;
}

